﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Report : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MonthSelectControl.DateChanged += new EventHandler(MonthSelectControl1_DateChanged);
        if (!IsPostBack)
        {

        }
    }
    private void MonthSelectControl1_DateChanged(object sender, EventArgs e)
    {

        DateTime dt = MonthSelectControl.Value;
        lblDate.Text = dt.ToString("MMM-yyyy");
        bindPackagesByMonth(dt);
    }

    private void bindPackagesByMonth(DateTime dt)
    {
        BLLReport bllReport = new BLLReport();
        gvPackage.DataSource = bllReport.ListPackagesByMonth(dt);
        gvPackage.DataBind();
    }


    protected void btnExport_Click(object sender, EventArgs e)
    {
        ExportGridView(gvPackage);
    }

    public override void VerifyRenderingInServerForm(Control control)
    {


        // Confirms that an HtmlForm control is rendered for the
        //specified ASP.NET server control at run time.


    }


    private void ExportGridView(GridView gv)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename=report_" + lblDate.Text + ".xls");
        Response.Charset = "";
        Response.ContentType = "application/vnd.ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        gv.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.Flush();
        Response.End();
    }
}